import { Suspense } from "react"
export const syncRouter = (table, routeMap = {}) => {
  let mRouteTable = []
  table.forEach(route => {
    routeMap[route.path] = route.mate
    mRouteTable.push({
      path: route.path,
      element: (
        <Suspense fallback={<div>路由加载ing...</div>}>
          <route.element />
        </Suspense>
      ),
      children: route.children && syncRouter(route.children, routeMap).mRouteTable
    })
  })
  return {
    mRouteTable,
    routeMap
  }
}

// 生成唯一ID
export const generateUID = () => {
  return (
    __s4() +
    __s4() +
    "-" +
    __s4() +
    "-" +
    __s4() +
    "-" +
    __s4() +
    "-" +
    __s4() +
    __s4() +
    __s4()
  );
};
const __s4 = () => {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
